<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //写入5行4列的表格 将帖子数组中数据填充到单元格中
    var arr=[
        ["第1条帖子","a","第2条帖子主要内容是","2021-02-14"],
        ["第2条帖子","b","第4条帖子主要内容是","2021-02-01"],
        ["第3条帖子","c","第3条帖子主要内容是","2021-02-23"],
        ["第4条帖子","d","第1条帖子主要内容是","2021-02-08"],
        ["第5条帖子","e","第5条帖子主要内容是","2021-02-18"]
    ];
    /*
    //截取前5个字符 后面内容用....表示
    var text="这是帖子5，主要内容是";
    var preview=text.slice(0,5);
    preview=preview+"......"
    document.write(preview);
    var arr=[3,2,5,1,9];
    var childArr=arr.sort();
    console.log(childArr);
    */
   var tbHeight="500px";
   var tbWidth="800px";
   document.write("<table border='1' height='"+tbHeight+"'width='"+tbWidth+"'>");
    function createList(arr){
        for(var i=0;i<arr.length;i++){
            document.write("<tr>");
                for(var j=0;j<arr[0].length;j++){
                    if(j==2){
                        arr[i][j]=arr[i][j].slice(0,5)+"..."
                    }
                    document.write("<td>");
                    document.write(arr[i][j]);
                    document.write("<td/>");
                }
            document.write("<tr/>")
        }
    }
    createList(arr);
    document.write("</table>");
    </script>
</html>